package com.ray.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.ray.bean.FeedOrderDetailBean;
import com.ray.bean.OrderBean;
import com.ray.bean.ProcedureBean;
import com.ray.bean.ProcessBean;
import com.ray.bean.WorkshopProductionCycleBean;
import com.ray.mapper.TestMapper;
import com.ray.mapper.WeiXinPeopleMapper;
import com.ray.util.WeiXinParamesUtil;
import com.ray.util.WeiXinUtil;
import com.ray.util.weixin.WeixinTemplateList;
import com.ray.util.weixin.WeixinTemplateSender;


@Service
public class TestService {
	
	
	@Autowired
	TestMapper testMapper;
	@Autowired
	WeiXinPeopleMapper weiXinPeopleMapper;
	@Autowired
	WeiXinService weiXinService;
	
	
	public void updateProdure() {
		List<ProcessBean> proList=testMapper.getProdure();
		testMapper.updateProdure(proList);
	}


	public void updateWorkShop() {
		List<WorkshopProductionCycleBean> proList=testMapper.getWork();
		testMapper.updateWorkShop(proList);
	}


	public void updateChiCun() {
		List<OrderBean> list=testMapper.getOirders();
		testMapper.updateChiCun(list);
	}

	/**
	 * 测试发送消息
	 * @param userId
	 */
	public void testSendMessage(String userId) {
		List<String> openIdList=weiXinPeopleMapper.getOpenIdByUserId(userId);
		String accessToken=weiXinService.getAccessToken(null); 
		JSONObject json=WeixinTemplateList.packJsonWatiApproval("您好！您有待审核的任务，请于1天内审核。", "报工审核", "卢叶锋", "18279187725", "2018-05-31", "订单 xxxx 数量 100", "不审核老子就不干了", null, null, null, null, null, null, "red");
		JSONObject json2=WeixinTemplateList.packJsonPermissionChange("权限变更提醒", "报工审核", "您被设为数控车间报工审核人员", "2018-05-21", "权限变更后您将可以审核数控车间报工数据", null, null, null, null, null);
		for(String openId:openIdList) {
			String xx=WeixinTemplateSender.sendWechatmsgToUser(openId, WeiXinParamesUtil.watiApprovalTemplateID, "https://8888.shinehao.net/weixin/index.html", json, accessToken);
			WeixinTemplateSender.sendWechatmsgToUser(openId, WeiXinParamesUtil.permissionChangeTemplateID, "https://8888.shinehao.net/weixin/index.html", json2, accessToken);
		}
	}

	/**
	 * 设置投料单明细id
	 */
	public void testSetFeedDetail() {
		List<FeedOrderDetailBean> listFeed=testMapper.getFeedDetail();
		testMapper.testSetFeedDetail(listFeed);
	}


	public void testSetPurchaseDetail() {
		List<FeedOrderDetailBean> listFeed=testMapper.tesGetPurchaseDetail();
		for(FeedOrderDetailBean feed:listFeed) {
			testMapper.testSetPurchaseDetail(feed);
		}
		
	}


	public void testSetInOutDetail() {
		List<FeedOrderDetailBean> listFeed=testMapper.getInOutDetail();
		for(FeedOrderDetailBean feed:listFeed) {
			testMapper.testSetInOutDetail(feed);
		}
		
	}


	public void testNull() {
		Map map=new HashMap();
		map.put("xx", null);
		testMapper.testNull(map);
	}


	//设置订单总投料数
	public void setOrderSumFeed() {
		   List<Map> orderFeedMap=testMapper.getOrderFeedMap();
		   for(Map map:orderFeedMap) {
			   testMapper.setOrderSumFeed(map);
		   }
	}
	
	
	
}
